//
// Created by xili on 2024/9/4 21:24.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimumOperations(string num) {
        int n = num.length();
        auto f = [&](string tail) {
            int i = num.rfind(tail[1]);
            if (i == string::npos || i == 0) {
                return n;
            }
            i = num.rfind(tail[0], i - 1);
            return i == string::npos ? n : n - i - 2;
        };
        int zero = n - (num.find('0') != string::npos);
        return min({zero, f("00"), f("25"), f("50"), f("75")});
    }
};;
